package com.yanqu.road.logic.sort;

import com.yanqu.road.entity.rank.xrank.XSeasonUserRank;
import com.yanqu.road.utils.string.StringUtils;

import java.util.Comparator;

public class XSeasonJinBiaoPeakRankSort implements Comparator<XSeasonUserRank> {

    @Override
    public int compare(XSeasonUserRank o1, XSeasonUserRank o2) {
        // 比较value
        int result = o2.getValue().compareTo(o1.getValue());
        if (result != 0) {
            return result;
        }
        long score1 = 0;
        if (!StringUtils.isNullOrEmpty(o1.getParam())) {
            score1 = Long.parseLong(o1.getParam());
        }
        long score2 = 0;
        if (!StringUtils.isNullOrEmpty(o2.getParam())) {
            score2 = Long.parseLong(o2.getParam());
        }
        // 比较下参数
        long score = score2 - score1;
        result =  score > 0 ? 1 : (score == 0 ? 0 : -1);
        if (result != 0) {
            return result;
        }
        // 比较时间
        long time = o1.getLastUpdateTime() - o2.getLastUpdateTime();
        result = time > 0 ? 1 : (time == 0 ? 0 : -1);
        return result;
    }
}
